from django.contrib.admin import site, ModelAdmin, TabularInline

from .models import (Document, Requirement, Section, MultiLineText,
                     Table, OneLineText, Alias, Image, File, Archive)

class DocumentInline(TabularInline):
   model = Document

class RequirementInline(TabularInline):
   model = Requirement

class SectionInline(TabularInline):
   model = Section
   
class OneLineTextInline(TabularInline):
   model = OneLineText

class MultiLineTextInline(TabularInline):
   model = MultiLineText

class TableInline(TabularInline):
   model = Table
   
class ImageInline(TabularInline):
   model = Image

class FileInline(TabularInline):
   model = File
   
class AliasInline(TabularInline):
   model = Alias
   fk_name = 'requirement'
   
class DocumentA(ModelAdmin):
   sace_on_top = True
   list_display = 'id', 'project', 'name', 'prefix', 'active', 'writeable'
   list_filter = 'active', 'writeable', 'project'
   inlines = RequirementInline,
   search_fields = 'name', 'prefix'

class RequirementA(ModelAdmin):
   save_on_top = True
   list_display = 'id', 'document', 'unique', 'order', 'parts', 'user', 'time', 'active', 'writeable'
   list_filter = 'active', 'writeable', 'user', 'document'
   inlines = SectionInline, OneLineTextInline, AliasInline, ImageInline, FileInline, MultiLineTextInline, TableInline
   search_fields = 'document__project__name', 'id'

class SectionA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'kind', 'text'
   list_filter = 'kind',
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class MultiLineTextA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'text'
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class TableA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'text'
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class OneLineTextA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'text'
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class ImageA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'image'
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class FileA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'file'
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class AliasA(ModelAdmin):
   list_display = 'project', 'document', 'requirement', 'alias'
   search_fields = 'requirement__document__project__name', 'requirement__document__name'

class ArchiveA(ModelAdmin):
   list_display = 'project', 'name', 'time'
   list_filter = 'project',
   search_fields = 'project__name', 'name'

register = site.register

register(Document, DocumentA)
register(Requirement, RequirementA)
register(Section, SectionA)
register(MultiLineText, MultiLineTextA)
register(Table, TableA)
register(OneLineText, OneLineTextA)
register(Image, ImageA)
register(File, FileA)
register(Alias, AliasA)
register(Archive,ArchiveA)
